<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="../css/stylesite.css" medial="all" />
<link rel="stylesheet" type="text/css" href="../css/styleleft.css" medial="all" />
<link rel="stylesheet" type="text/css" href="../css/style.css" medial="all" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

	<script src="../js/jquery-1.8.2.min.js" ></script>
	<script src="../js/image.js" type="text/javascript"></script>
        <script src="../js/jsearch.js" type="text/javascript"></script>  
	<script src="../js/stickytooltip.js" ></script>
	<link rel="stylesheet" type="text/css" href="../css/stickytooltip.css"/>
	<script type="text/javascript">
	
	</script>
<title>Sản Phẩm</title>
</head>

<body class="pagebody">
	<div id="wrapwebsite" >
				<?php 
			include('../element/header.php');
			
			?>
			<div class="imagestop"></div>
			<div class="wrapmaincontent">
		<?php
		include('../element/leftside.php');
		?>
		<div class="center-leftmargin">
                  <?php include ('product_model.php'); ?>
				<?php   if (isset( $_GET['categoryId'])){ $categoryid=$_GET['categoryId'];}
				if (isset( $_GET['name'])){$name=$_GET['name']; }
					$display=3;
				   if(isset($_GET['page']) && (int)$_GET['page']) {
               			 $page = $_GET['page'];
           		 } else {
				 		if(countRowsByCategory($categoryid)>$display)
						$page=ceil(countRowsByCategory($categoryid)/$display);
						else $page=1;
					}
				$start = (isset($_GET['start']) && (int)$_GET['start']>=0) ? $_GET['start'] : 0;
				  $products= getByCategory($categoryid,$start, $display);?>
				   <div class="products">
				    <div class="moduletitle"><h2><?php echo $name;?></h2></div>
				  <div class="modulecontent">
				 
				  <?php
				  $i=1;
				 
				  foreach ($products as $product)
				  {
				  		$name ='product'.$i;
				  		$_SESSION[$name]=$product;
				   		?>
						 
						<div class="productitem">
						<div class="wrapimages">
						<div class="image"><img data-tooltip="sticky<?php echo $i;?>" src="<?php echo $product[3];?>"/></div>
						</div>
						<div class='slOf_flag'>
						<?php if ($product[9]>0)
							
							{ $dis=$product[9];
							echo "
					<span class='slOf_sale'>-$dis%</span>";
						}?></div>
						<div class="content">
						<div class="productname"><a href="ProductDetail.php?i=<?php echo $i;?>"><?php echo $product[1];?></a></div>
						
						</div>
						</div>
						<?php $i++;
				  }
				   ?>
				  <div class="pagging">
				   <ul class="nav">
				<?php 
					if($page > 1) { //neu can hien thi so trang
						
						$next = $start + $display;
						$prev = $start - $display;
						$current = ($start/$display)+1;
						
						//Hien thi trang Previous
						if($current !=1) {
						echo "<li><a href='ProductByCategory.php?start=$prev&page=$page&categoryId=$categoryid&name=$name'>Previous</a></li>";
						}
						//Hien thi so link
						for($i=1;$i<=$page;$i++) {
							if($current != $i) {
							echo "<li><a href='ProductByCategory.php?start=".($display*($i-1))."&page=$page&categoryId=$categoryid&name=$name'>$i</a></li>";
						} else {
							echo "<li class='current'>$i</li>";
						}
						} //End: FOR
						
						//Hien thi trang Next
						
						if($current != $page) {
							echo "<li><a href='ProductByCategory.php?start=$next&page=$page&categoryId=$categoryid&name=$name'>Next</a></li>";
						}
						
					}//End: $page > 1 IF
				?>
        		</ul>
				  </div>
				   </div>
				     <?php
				  $j=1;?>
				  <div id="mystickytooltip" class="stickytooltip">
				 <div style="padding:5px">
				  <?php
				  foreach ($products as $product)
				  {
				   		?>
						
						<div id="sticky<?php echo $j;?>" class="atip" style="width:230px; min-height:100px;">
						<img src="<?php echo $product[3];?>" align="middle"  style="float:left; padding-right:10px; max-width:220px" />
						<p style=""><span style=" font-size:17px; color:#CC0000;font-style:italic; font-family:Times New Roman"><?php echo $product[1];?></span><br>
						<?php if($product[9]>0)
						{
						   $dis=$product[9];
						   $tk=$product[4]*$dis/100;
						   $pri=$product[4]-$tk;
							echo "Giá bán:<span style='color:#FF0000; font-size:17px;'>$pri  VND<br></span> Giá ban đầu:<span style='text-decoration:line-through; color:#999999; '> $product[4] VND</span><br> Tiết kiềm:$tk VND<br>";
						} else {?>
						 Giá Bán: <?php echo $product[4];?>&nbsp;&nbsp;VND<br><?php }?>
						 Số lượt xem: <?php echo $product[8];?></p>
						
						</div>
						
						<?php
						$j++;
				  }
				   ?></div>
				    <div class="stickystatus"></div>
					</div>
				   </div>
				   </div>
				
		</div>
		
		
		<?php include('../element/footer.php'); ?>
</div>
</body>
</html>
